//用户相关接口
import request from "@/utils/request.ts";
import type { userResponseData, userObj } from "./type";

enum API {
  // DELETE
  batchRemove = "/admin/acl/user/batchRemove",
  // 根据id列表删除管理用户

  // POST
  doAssign = "/admin/acl/user/doAssign",
  // 根据用户分配角色

  // POST
  doAssignRole = "/admin/acl/user/doAssignRole",
  // 根据用户分配角色

  // GET
  get = "/admin/acl/user/get",
  // 获取管理用户

  // DELETE
  remove = "/admin/acl/user/remove",
  // 删除管理用户

  // POST
  save = "/admin/acl/user/save",
  // 新增管理用户

  // GET
  toAssign = "/admin/acl/user/toAssign",
  // 根据用户获取角色数据

  // PUT
  update = "/admin/acl/user/update",
  // 修改管理用户

  // GET
  user = "/admin/acl/user",
  // 获取管理用户分页列表
}

export const batchRemove = (dataArr: any) => {
  let data: any = { data: dataArr };
  return request.delete<any, any>(API.batchRemove, data);
};

export const doAssign = (data: any) =>
  request.post<any, any>(API.doAssign, data);

export const doAssignRole = (roleIdList: any[], userId: any) => {
  let data = {
    roleIdList,
    userId,
  };
  return request.post<any, any>(API.doAssignRole, data);
};

export const get = (id: number) => request.get<any, any>(API.get + `/${id}`);

export const remove = (id: number) =>
  request.delete<any, any>(API.remove + `/${id}`);

export const save = (data: userObj) => request.post<any, any>(API.save, data);

export const toAssign = (id: number) =>
  request.get<any, any>(API.toAssign + `/${id}`);

export const update = (data: any) => request.put<any, any>(API.update, data);

export const user = (pageNo: number, limit: number, username: string) => {
  if (username.length <= 0) {
    return request.get<any, userResponseData>(API.user + `/${pageNo}/${limit}`);
  } else {
    return request.get<any, userResponseData>(
      API.user + `/${pageNo}/${limit}?username=${username}`,
    );
  }
};
